package com.example.lab.listener;

import com.example.lab.event.LaboratoryStatusChangedEvent;
import com.example.lab.service.ILabManagersService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 实验室状态变更事件监听器
 */
@Component
@RequiredArgsConstructor
public class LaboratoryEventListener {

    private final ILabManagersService labManagersService;

    /**
     * 当实验室状态变为“禁用”时，自动清理关联管理员
     */
    @EventListener
    public void handleLaboratoryDisabled(LaboratoryStatusChangedEvent event) {
        if (!event.isEnabled()) {
            labManagersService.removeByLabId(event.getLabId());
        }
    }
}
